﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SisLegal.Model; 

namespace SisLegal.Maestros
{
    public partial class CrimeListView : System.Web.UI.Page
    {
        CrimeGenericManager crimeGeneric;
        CrimeSubGenericManager crimeSubGeneric;
        CrimeSpecificManager crimeSpecific;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                crimeGeneric = new CrimeGenericManager();
                RstGenericTable.DataSource = crimeGeneric.Paginate(1);
                RstGenericTable.DataBind();

                double xx = Convert.ToDouble(crimeGeneric.Count()) / 10;
                double tt = Math.Ceiling(xx);

                List<Item> items = new List<Item>();
                for (int x = 1; x <= tt; x++)
                {
                    items.Add(new Item() { NumPage = x });
                }
                Repeater_Paginate_Generic.DataSource = items;
                Repeater_Paginate_Generic.DataBind();
                //-----------------------------------------
                crimeSubGeneric = new CrimeSubGenericManager();
                RstSubGenericTable.DataSource = crimeSubGeneric.Paginate(1);
                RstSubGenericTable.DataBind();

                xx = Convert.ToDouble(crimeSubGeneric.Count()) / 10;
                tt = Math.Ceiling(xx);

                items = new List<Item>();
                for (int x = 1; x <= tt; x++)
                {
                    items.Add(new Item() { NumPage = x });
                }
                Repeater_Paginate_SubGeneric.DataSource = items;
                Repeater_Paginate_SubGeneric.DataBind();
                //-----------------------------------------
                crimeSpecific = new CrimeSpecificManager();
                RstSpecificTable.DataSource = crimeSpecific.Paginate(1);
                RstSpecificTable.DataBind();

                xx = Convert.ToDouble(crimeSpecific.Count()) / 10;
                tt = Math.Ceiling(xx);

                items = new List<Item>();
                for (int x = 1; x <= tt; x++)
                {
                    items.Add(new Item() { NumPage = x });
                }
                Repeater_Paginate_Specific.DataSource = items;
                Repeater_Paginate_Specific.DataBind();
                //-----------------------------------------
            }
        }

        protected void Paginate_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Paginate_Generic")
            {
                String num = e.CommandArgument.ToString();
                crimeGeneric = new CrimeGenericManager();
                RstGenericTable.DataSource = crimeGeneric.Paginate(Convert.ToInt32(num));
                RstGenericTable.DataBind();
            }
            if (e.CommandName == "Paginate_SubGeneric")
            {
                String num = e.CommandArgument.ToString();
                crimeSubGeneric = new CrimeSubGenericManager();
                RstSubGenericTable.DataSource = crimeSubGeneric.Paginate(Convert.ToInt32(num));
                RstSubGenericTable.DataBind();
            }
            if (e.CommandName == "Paginate_Specific")
            {
                String num = e.CommandArgument.ToString();
                crimeSpecific = new CrimeSpecificManager();
                RstSpecificTable.DataSource = crimeSpecific.Paginate(Convert.ToInt32(num));
                RstSpecificTable.DataBind();
            }
        }
    }
}